package com.oocl.zero.datahandle;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

import com.oocl.zero.datahandle.action.impl.TCPAppAction;
import com.oocl.zero.datahandle.entity.Customer;
import com.oocl.zero.datahandle.util.CustomerParser;

/**
 * Hello world!
 *
 */
public class App 
{
	
	private static final String FILENAME = "db.txt";
	private static Set<Customer> set=new HashSet<>();
	static{
		dataInit();
//		printDatas();
	}

	private static void printDatas() {
		for (Customer c : set) {
			System.out.println(c);
		}
	}
	
    public static void main( String[] args )
    {
		int port = 8883;
		new TCPAppAction(port ).start();
    }
    private static void dataInit() {
    	try {
			Scanner sc=new Scanner(new FileInputStream(new File(FILENAME)));
			String splitRegex="\\s+";
			String line;
			while(sc.hasNext()){
				line= sc.nextLine();
				Customer c = CustomerParser.doParse(line,splitRegex);
				if(c!=null){
					set.add(c);
				}
	        }
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		};
		
	}
	// db getData
	public static Set<Customer> getDatas() {
		return set;
	}
}
